added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2010 / CSASPNETAJAXWebChat / Logic / ChatRoom.cs
blob31bf35dfede92e1b7e6bf0f6faa34c2d1ffbabb1
1 /****************************** Module Header ******************************\
2 * Module Name: ChatRoom.cs
3 * Project: CSASPNETAJAXWebChat
4 * Copyright (c) Microsoft Corporation
6 * The project illustrates how to design a simple AJAX web chat application.
7 * We use jQuery, ASP.NET AJAX at client side and Linq to SQL at server side.
8 * In this sample, we could create a chat room and invite someone
9 * else to join in the room and start to chat.
11 * In this file, we create a DataContract class which used to serialize the
12 * ChatRoom data to the client side.
14 * This source is subject to the Microsoft Public License.
15 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
16 * All other rights reserved.
18 \*****************************************************************************/
20 using System;
21 using System.Linq;
22 using System.Web;
23 using System.Runtime.Serialization;
25 namespace WebChat.Logic
27 [DataContract]
28 public class ChatRoom
30 [DataMember]
31 public Guid RoomID { get; private set; }
32 [DataMember]
33 public string RoomName { get; private set; }
34 [DataMember]
35 public int MaxUser { get; private set; }
36 [DataMember]
37 public int CurrentUser { get; private set; }
39 public ChatRoom(Guid id)
41 WebChat.Data.SessionDBDataContext db = new Data.SessionDBDataContext();
42 var room = db.tblChatRooms.SingleOrDefault(r => r.ChatRoomID == id);
43 if (room != null)
45 RoomID = id;
46 RoomName = room.ChatRoomName;
47 MaxUser = room.MaxUserNumber;
48 CurrentUser = room.tblTalkers.Count(t => t.CheckOutTime == null);